package com.xieke.admin.web;

import com.xieke.admin.dto.ResultInfo;
import com.xieke.admin.service.ICodeService;
import com.xieke.admin.service.IHisTjDjbService;
import org.apache.commons.io.IOUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 数据表 前端控制器
 * </p>
 *
 * @author 邪 客
 * @since 2018-12-25
 */
@Controller
@RequestMapping("/chat")
public class ChatController extends BaseController {

    @Resource
    private ICodeService iCodeService;
    @Autowired
    private IHisTjDjbService iHisTjDjbService;

    @RequestMapping("/*")
    public void toHtml(){

    }

    @RequestMapping("/listData")
    @RequiresPermissions("chat:view")
    public @ResponseBody
        ResultInfo<Map<String, Object>> listData(String tableName, Integer page, Integer limit){

        Map<String, Object> map = new HashMap<>();
        map.put("tableName", tableName);
        map.put("offset", (page - 1) * limit);
        map.put("limit", limit);
        List<Map<String, Object>> mapList = iCodeService.queryList(map);
        for (Map m : mapList){
            m.put("createTime", String.valueOf(m.get("createTime")).substring(0,19));
        }
        int total = iCodeService.queryTotal(map);

        return new ResultInfo(mapList, total);
    }

    /**
     * 获取首页图表信息
     * @return
     */
    @RequestMapping("/homeChart")
    public @ResponseBody
    ResultInfo<Map<String, Object>> homeChart(){
        return new ResultInfo(iHisTjDjbService.queryListForJGName());
    }


    /**
     * 获取首页图表信息
     * @return
     */
    @RequiresPermissions("chat:view")
    @RequestMapping("/medicalDiseases")
    public @ResponseBody
    ResultInfo<Map<String, Object>> medicalDiseases(int limit){
        return new ResultInfo(iHisTjDjbService.queryListForMedicalDiseases(limit));
    }

    /**
     * 获取首页图表信息
     * @return
     */
    @RequiresPermissions("chat:view")
    @RequestMapping("/yearMedicalDiseases")
    public @ResponseBody
    ResultInfo<Map<String, Object>> yearMedicalDiseases(){
        return new ResultInfo(iHisTjDjbService.queryListForYearMedicalDiseases());
    }

    /**
     * 获取首页图表信息
     * @return
     */
    @RequestMapping("/homeChart_map")
    public @ResponseBody
    ResultInfo<Map<String, Object>> homeChart_map(String JGMC){
        return new ResultInfo(iHisTjDjbService.queryListForQYJG(JGMC));
    }
}